//
//  myButton.m
//  项目一
//
//  Created by nick on 15/7/17.
//  Copyright (c) 2015年 nick. All rights reserved.
//

#import "myButton.h"

@implementation myButton
- (id)initWithFrame:(CGRect)frame withLable:(NSString *)lable withImage:(NSString *)image{
    self = [super initWithFrame:frame];
    _btnLable = [[UILabel alloc]initWithFrame:CGRectZero];
    _btnLable.text = lable;
    _btnLable.textAlignment = NSTextAlignmentCenter;
    _btnLable.font = [UIFont systemFontOfSize:11];
    _btnLable.textColor = [UIColor whiteColor];
    
    _image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:image]];
    _image.contentMode = UIViewContentModeScaleAspectFit;
    [self addSubview:_btnLable];
    [self addSubview:_image];
    return self;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    CGRect frame1 = _image.frame;
    CGRect frame2 = _btnLable.frame;
    CGFloat width = self.frame.size.width;
   // CGFloat heitht = self.frame.size.height;
    frame1 = CGRectMake((width-20)/2, 5, 20, 20);
    frame2 = CGRectMake(0, CGRectGetMaxY(frame1), width, 20);
    _image.frame = frame1;
    _btnLable.frame =frame2;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
